package c.x.jy.dao.dao;

import c.x.jy.dao.dto.ServiceEntityDto;
import c.x.jy.dao.dto.TeacherServiceEntityDto;
import c.x.jy.dao.entity.TeacherServiceEntity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 大师高级项目配置表
 * 
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-24 10:50:04
 */
@Mapper
public interface TeacherServiceDao extends BaseMapper<TeacherServiceEntity> {

	@Select(" SELECT s.* , tr.id as itemId,tr.original_price as originalPrice,tr. discount_price as discountPrice ,tr.description as description , tr.create_date as createDate FROM `t_service` t LEFT JOIN t_teacher_service tr on tr.service_id =t.id WHERE tr.member_id =${memberId} ")
	List<ServiceEntityDto> selectServiceBymemberId(Long memberId);

	@Select(" SELECT s.*, tr.service_title as serviceTitle,tr.id as itemId,tr.original_price as originalPrice,tr. discount_price as discountPrice ,tr.description as description , tr.create_date as createDate FROM `t_service` s LEFT JOIN t_teacher_service tr on tr.service_id =s.id LEFT JOIN t_teacher t on t.member_id=tr.member_id   WHERE t.id =${teacherId} ")
	List<ServiceEntityDto> selectServiceByTeacherId(Long teacherId);

	@Select("SELECT tr.* ,s.title as itemName ,tr.original_price as originalPrice,tr. discount_price as discountPrice ,tr.description as description , tr.create_date as createDate ,s.image as image,s.mini_image as miniImage FROM `t_teacher_service` tr LEFT JOIN t_service s on s.id=tr.service_id  WHERE tr.id=${id}  ")
	ServiceEntityDto selectServiceInfoById(Long id);

	@Update("<script>INSERT INTO `t_teacher_service` (`member_id`, `service_id`, `service_title`, `original_price`,`discount_price`,`description`,`create_id`,`teacher_id`) VALUES   <foreach collection='list' item='item' index='index'  separator=','> (  #{item.memberId},#{item.serviceId},#{item.serviceTitle},#{item.originalPrice},#{item.discountPrice},#{item.description},#{item.createId},#{item.teacherId}    )  </foreach> </script>  ")
	int insertServiceList(List<TeacherServiceEntity> list);

	@Select(" SELECT * from `t_teacher_service`  where  id=${id}  for update ")
	TeacherServiceEntity selectTezcherServiceForUpdate(Long id);

	@Select(" select ts.*,m.nickname as memberName,t.nickname as teacherName,s.title as serviceName from ((t_teacher_service ts LEFT JOIN t_member m on m.id=ts.member_id) LEFT JOIN t_teacher t on t.member_id=m.id)LEFT JOIN t_service s on s.id=ts.service_id  ${ew.customSqlSegment}")
    IPage<TeacherServiceEntityDto> listforweb(IPage<TeacherServiceEntity> page,@Param(Constants.WRAPPER)   QueryWrapper<TeacherServiceEntity> query);
}
